package cn.edu.scau.cmi.xuchuangxiong.client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import cn.edu.scau.cmi.xuchuangxiong.singleton.Chairman;
import cn.edu.scau.cmi.xuchuangxiong.singleton.Marshal;
import javafx.scene.control.Label;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextArea;

public class MultipletonClient extends JFrame {

	private JPanel contentPane;
	private JLabel label;
	private JTextField textField;
	private JButton button;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MultipletonClient frame = new MultipletonClient();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MultipletonClient() {
		this.setTitle("实验2：多例模式");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 378, 449);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JTextArea textArea = new JTextArea();
		textArea.setBounds(20, 90, 318, 298);
		contentPane.add(textArea);
		textField = new JTextField();
		textField.setBounds(60, 31, 110, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		button = new JButton("创建");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Marshal marshal = Marshal.getRandomInstance(textField.getText());
				if(marshal == null) textArea.append("十大元帅已创建完毕，已不能再行创建！\n");
				else textArea.append(marshal.getName()+marshal.toString()+"\n");
			}
		});
		button.setBounds(197, 30, 72, 23);
		contentPane.add(button);

		

	}
}
